# VideoScreen - This screen allows user to browse video library content
# Copyright (C) 2007 Lauri Taimila
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

__licence__ = "GPLv2"
__copyright__ = "2008, Lauri Taimila"
__author__ = "Lauri Taimila <lauri@taimila.com>"

import clutter
from frontend.gui.screens.screen import Screen

# Widgets
from frontend.gui.tabs.tab import Tab
from frontend.gui.widgets.tab_group import TabGroup
from frontend.gui.tabs.movies_tab import MoviesTab
from frontend.gui.tabs.series_tab import SeriesTab
from frontend.gui.tabs.video_clips_tab import VideoClipsTab
from frontend.gui.tabs.music_videos_tab import MusicVideosTab

class VideoScreen(Screen):
    """
    VideoScreen
    
    This screen contains tabs for different video types. This is the top level
    UI for video library.
    """
    
    def __init__(self, ui, frontend):
        """
        Initialize screen
        
        @param frontend: FrontendClient object
        @param theme: Theme object
        """
        self.group = clutter.Group()
        Screen.__init__(self, ui.STAGE_WIDTH, ui.STAGE_HEIGHT)
        
        self.ui = ui
        self.frontend = frontend
        self.theme = frontend.getTheme()
        self.library = self.frontend.get_video_library()
        
        # Screen Title (Displayed at the bottom left corner)
        screen_title = clutter.Label()
        screen_title.set_font_name(self.theme.getFont() + " " + str(self.ui.y(0.13)) + "px")
        screen_title.set_color(self.theme.getColor("screentitle"))
        screen_title.set_text("Videos")
        screen_title.set_name("screen_title")
        screen_title.set_position(self.ui.x(0), self.ui.y(0.87))
        screen_title.show()
        self.group.add(screen_title)
        
        # Tabs
        self.tab_group = TabGroup(0.95, 0.13, self.theme.getColor("title"))
        tab1 = MoviesTab("Movies", self.frontend)
        tab2 = SeriesTab("TV-Series", self.frontend)
        #tab3 = MusicVideosTab("Music videos", self.frontend)
        tab4 = VideoClipsTab("Video clips", self.frontend)
        self.tab_group.add_tab(tab1)
        self.tab_group.add_tab(tab2)
        #self.tab_group.add_tab(tab3)
        self.tab_group.add_tab(tab4)
        self.tab_group.set_y(self.ui.y(0.1))
        self.tab_group.set_anchor_point_from_gravity(clutter.GRAVITY_CENTER)
        self.tab_group.set_x(self.ui.x(0.5))
        self.tab_group.show()
        self.tab_group.set_active(True)
        self.group.add(self.tab_group)

        self.group.add(tab1)
        self.group.add(tab2)
        #self.group.add(tab3)
        self.group.add(tab4)
        
        self.group.show()
        ui.getStage().add(self.group)
    
    def get_group(self):
        """
        Get all actors of the screen.
        @return clutter.Group 
        """
        return self.group

    def get_type(self):
        """
        Get screen type.
        @return: Integer (Constant variable from Screen class)
        """
        return Screen.NORMAL
    
    def get_name(self):
        """
        Get screen name (human readable)
        @return: String
        """
        return "VideoScreen"
    
    def handle_user_event(self, event):   
        """ 
        Handle screen specific user events
        @param event: UserEvent object
        """
        self.tab_group.handle_user_event(event)